package com.toptech.downloadmanager;

import android.os.Parcel;
import android.os.Parcelable;

/**
 * Created by zhengshaorui on 2017/2/27.
 */

public class DownloadConfigGuration implements Parcelable{

    private static int THREAD_COUNT_MAX = 10;//最大线程数为10
    private String filename;
    private String fileurl;
    private int threadcount;
    private int priority;


    protected DownloadConfigGuration(Parcel in) {
        filename = in.readString();
        fileurl = in.readString();
        threadcount = in.readInt();
        priority = in.readInt();
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(filename);
        dest.writeString(fileurl);
        dest.writeInt(threadcount);
        dest.writeInt(priority);
    }

    @Override
    public int describeContents() {
        return 0;
    }

    public static final Creator<DownloadConfigGuration> CREATOR = new Creator<DownloadConfigGuration>() {
        @Override
        public DownloadConfigGuration createFromParcel(Parcel in) {
            return new DownloadConfigGuration(in);
        }

        @Override
        public DownloadConfigGuration[] newArray(int size) {
            return new DownloadConfigGuration[size];
        }
    };

    public String getFilename() {
        return filename;
    }

    public void setFilename(String filename) {
        this.filename = filename;
    }

    public String getFileurl() {
        return fileurl;
    }

    public void setFileurl(String fileurl) {
        this.fileurl = fileurl;
    }

    public int getThreadcount() {
        return threadcount;
    }

    public void setThreadcount(int threadcount) {
        if (threadcount >= THREAD_COUNT_MAX){
            threadcount = THREAD_COUNT_MAX;
        }
        this.threadcount = threadcount;
    }

    public int getPriority() {
        return priority;
    }

    public void setPriority(int priority) {
        this.priority = priority;
    }

    public DownloadConfigGuration() {
    }



    public DownloadConfigGuration(Builder builder) {


        this.fileurl = builder.fileurl;
        this.filename = builder.filename;
        this.threadcount = builder.threadcount;
        this.priority = builder.priority;
    }

    @Override
    public String toString() {
        return "DownloadConfigGuration{" +
                ", filename='" + filename + '\'' +
                ", fileurl='" + fileurl + '\'' +
                ", threadcount=" + threadcount +
                ", priority=" + priority +
                '}';
    }


    public static class Builder{
        private String filename;
        private String fileurl;
        private int threadcount;
        private int priority;

        public Builder(){}

        public Builder setUrl(String url){
            this.fileurl = url;
            return this;
        }
        public Builder setName(String name){
            this.filename = name;
            return this;
        }
        public Builder setThreadCount(int threadcount){
            if (this.threadcount >= THREAD_COUNT_MAX) this.threadcount = THREAD_COUNT_MAX;
            else this.threadcount = threadcount;
            return this;
        }
        public Builder setPriority(int priority){
            this.priority = priority;
            return this;
        }

        public DownloadConfigGuration build(){
            return new DownloadConfigGuration(this);
        }
    }
}


